//index.js
//获取应用实例
const app = getApp()

Page({
  data : {
    imagePath: ''
  },
  onLoad: function () {
    // 设置全局图片路径
    this.setData({
      imagePath: app.globalData.imagePath
    });
  },
  getUserInfo: function (res) {
    var that = this;

    wx.showLoading({
      title: '登录中',
    })

    wx.request({
      url: app.globalData.apiUrl + 'user/addUserAuth',
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
        "Cookie": "PHPSESSID=" + wx.getStorageSync('sessionID')
      },
      data: {
        encryptedData: res.detail.encryptedData,
        iv: res.detail.iv,
        rawData: res.detail.rawData,
        signature: res.detail.signature
      },
      success: function (res) {

        if (app.globalData.from_url == '/pages/my/my') {
          wx.redirectTo({
            url: app.globalData.from_url
          });
        } else if (app.globalData.from_url == '/pages/toAction/toAction') {
          wx.redirectTo({
            url: app.globalData.from_url
          })
        } else if (app.globalData.from_url == '') {
          wx.switchTab({
            url: '/pages/index/index'
          });
        }
        wx.hideLoading();
      },
      fail:function(res) {
        app.reportError(res.errMsg, 'login-getUserInfo-user/addUserAuth');
      }
    });
  }
})
